function showDialog(obj){
    if("add" == obj){
        $(".PopupTitle").html("新建用户信息");
        $("#add").modal("show");
    }else{
        $(".PopupTitle").html("修改用户信息");
        $("#add").modal("show");
    }

}

/*外部借用*/
function afterClickExtemalUseTab(){
    getExtemalUseList();//获取list列表
}
/*条件查询*/
function queryExtemalUse(){
    var code=$("#extemalUseForm").validationEngine("validate");//验证表单
    if(!code){
        return;
    }
    var date=$("#extemalUseForm").serializeFormJSON();/*序列化json*/
    $("#extemalUse").selectDataAfterSetParm(data_);/*查询数据设置参数*/
}

/*新建*/
function addExtemalUse (){
    var customNumber = $.trim($("#customNumber").val());
    var modelNumber = $.trim($("#modelNumber").val());
    var uniqueCide = $.trim($("#uniqueCide").val());
    /*  var stata = $("#stateDiv").children().text();*/
    var startDate = $.trim($("#startDate").val());
    var endDate = $.trim($("#endDate").val());
    var remark = $.trim($("#remark").val());

    if("" == customNumber ){
        alert("请输入设备编号");
        return false;
    }else if("" == modelNumber ){
        alert("请输入设备型号");
        return false;
        /*  }else if("服务中" != state && "未服务" != state){
         alert("请选择设备状态");
         return false;*/
    }else if("" == uniqueCide ){
        alert("请输入唯一标识码");
        return false;
    }else if("" == startDate ){
        alert("请选择借用时间");
        return false;
    }else if("" == endDate ){
        alert("请选择归还时间");
        return false;
    }else{
        var data = {"customNumber":customNumber,"modelNumber":modelNumber,"uniqueCide":uniqueCide,"startDate":startDate,"endDate":endDate}
        $().invoke(p_path + "/eqpt/equipment/extemalUse/addExtemalUse.json",data,[function(m,r){
            if(1==r){
                alert("保存成功");
                $("#xjsb").modal("hide");
                $("#extemalUse").refresh();
//				window.location.href = pagePath + "/settings/user/getUserManagerIndex.html";
            }
        }]);
    }
}


/*删除*/
var id=1;
function delExtemalUse(id,idList){
    if(isEmpty(id)){
        attr("没有选择项!");
        return false;
    }
    if(!confirm("是否确定删除!")){
        return;
    }
    $().invoke(                                                       /*多个删除使用idList传值*/
        p_path+"/eqpt/equipment/extemalUse/delExtemalUse.json",{"id":id,"idList":idList},[function(m,r){
            if(r=="success"){
                $("ExtemalUse").refresh();
            }
        },function(m,r){
            alert(r);
        }]
    )
}
/*列表数据*/
function getExtemalUse(){
    var col=[
             {title:checkHtml(),name:"SHORT_NAME",width:"5%",align:"center",format:checkHtml},
             {title:"设备编号",name:"customNumber",width:"10%",align:"center"},
            {title:"型号",name:"modelNumber",width:"10%",align:"center"},
            {title:"领用单位",name:"useCompany",width:"10%",align:"center"},
            {title:"领用人",name:"useUser",width:"10%",align:"center"},
            {title:"联系电话",name:"mobile",width:"10%",align:"center"},
            {title:"领用日期",name:"startDateStr",width:"10%",align:"center"},
            {title:"预计归还日期",name:"planEndDateStr",width:"10%",align:"center"},
            {title:"编辑",name:"id",width:"8%",align:"center",format:dataEdit},
            {title:"删除",name:"id",width:"7%",align:"center",format:dataDeatil}
//            {title:"删除",name:"id",width:"5%",align:"center",format:dataDeatil}
            ];

    new page(".content-inner",col);
}
//调用列表
$(function(){
    $(".add").click(function(){

        $('.tk').show();
        $('.tk').attr("url",$(this).attr("url"));
        $(".tk .tk-header span").html("新建内部领用");
        $(".tk").initData();
    })
    $(".save").click(function(){
        $('.tk').submit(function(){
            $('.tk').hide();
            initSelect($(".tk").find("select[data-name='eqptEquipmentId']"));
            $(".tabBox").refresh();
        });

    })
    $(".tk-header em").click(function(){
        initSelect($(".tk").find("select[data-name='eqptEquipmentId']"));
        $('.tk').hide();
    })
    $(".delAll").click(function(){
        var param=new Array();
        $(".tabBox input:checkbox").each(function(){
            param.push({"name":"id","value":$(this).val()});
        })
        if(param.length == 0)
        {
            alert("请选择需要删除的数据!");
            return;
        }


        if(confirm("请确定是否删除?"))
        {
            resultAjax($(this).attr("url"),param,function(){
                $(".tabBox").refresh();
            },"JSON");
        }
    })
    getExtemalUse();
})
//选择框
function checkHtml(data){
	var id=null;
	if(data != undefined)
	{
		id=data["id"];
	}
    return  '&nbsp;<input id="JQ_check_all" value="'+id+'" type="checkbox">&nbsp;';
}
function dataDeatil(json){
    var result='';
    result+='<img class="icon-img del" tag="delUrl"  alt="" src="'+p_path+'/static/img/delete.png">';
    return result;
}
function dataEdit(json){
    var result='';
    result+='<img class="icon-img edit" title="编辑设备领用信息" url="'+p_path+'/eqpt/equipment/extemalUse/updateExtemalUse.json" modal=".tk" alt="" src="'+p_path+'/static/img/icon_edit.png">';

    return result;
}



function extemalUseRowClick(data,obj,orderNum){
    try {
        var eventTarget_ = event.target || event.srcElement;
        if (eventTarget_ != null && eventTarget_ != document&& eventTarget_.tagName=="EM") {
            if ($(eventTarget_).hasClass("delet2")) {
                return;
            }
        }
    } catch (e) {
        console.log(e)
    }
    return false;
}



function extemalUseCilck(data,obj,orderNum){
    try{
        var eventTarget_= event.target || event.srcElement;
        if (eventTarget_ != null && eventTarget_ != document&& eventTarget_.tagName=="EM") {
            if ($(eventTarget_).hasClass("delet2")) {
                return;
            }
        }
    } catch (e) {
        console.log(e)
    }

    var t=$("#ExtemalUse"+orderNum,$("#ExtemalUse"));
    $("td",t).html(showTrackPointUl(data));
    t.fadeToggle();
    return false;

}


function updataCrossOver(id){
    if(isEmpty("id")){
        attr("id不能为空!");
        return;
    }
    $(id).invoke(
        p_path+"/eqpt/equipment/extemalUse/updateExtemalUse.json",
        {"id":id},
        [function(m,r){
            if (r=='success'){
                $("#extemalUse").refresh();
            }
        },function(m,r){
            alert(r);
        }]
    )
}
/*新增*/
function  addEquipmentInfo(adddata){
    $().invoke(
        p_path+"eqpt/addExtemalUse.json",{"userId":userId,"startDate":startDate,"endDate":endDate,"updateRemark":updateRemark},[function(m,r){
            if(r=="success"){
                $("ExtemalUse").refresh();
            }
        },function(m,r){
            alert(r);
        }]

    )
}

/*编辑更新*/
function  updateExtemalUse(id) {
    $().invoke(
        p_path + "eqpt/updateExtemalUse.json", {
            "id": id,
            "userId": userId,
            "startDate": startDate,
            "endDate": endDate,
            "updateRemark": updateRemark
        }, [function (m, r) {
            if (r == "success") {
                $("ExtemalUse").refresh();
            }
        }, function (m, r) {
            alert(r);
        }]
    )
}

/*function dataDeatil(json){
 var h="<li class=\"w12-4-3-1 no-right\" style='list-style: none;'>" +
 "<em class=\"xq-icon\"></em>" +
 "<em onclick=delCrossOver('"+json.id+"') class=\"delet2\"></em></li>";
 return h;
 }*/

